import storage from 'good-storage'
import { notification } from 'antd'

// 成功通知提醒框
export const successNotify = (configs) => {
  notification.success(configs)
}

// 失败通知提醒框
export const errorNotify = (configs) => {
  notification.error(configs)
}

// 获取和设置本地存储
export const getLocalStorage = (name, val) => {
  if (val) {
    return storage.set(name, val)
  }
  return storage.get(name)
}

// 删除本地存储
export const removeLocalStorage = (name) => {
  storage.remove(name)
}

export const getBodySize = () => {
  const body = document.body

  return {
    width: body.clientWidth,
    height: body.clientHeight
  }
}

const elementStyle = document.createElement('div').style
const vendor = (() => {
  const transformNames = {
    webkit: 'webkitTransform',
    Moz: 'MozTransform',
    O: 'OTransform',
    ms: 'msTransform',
    standard: 'transform'
  }

  for (const key in transformNames) {
    if (elementStyle[transformNames[key]] !== undefined) {
      return key
    }
  }

  return false
})()

// 行内样式兼容写法
export const prefixStyle = style => {
  if (vendor === false) {
    return false
  }

  if (vendor === 'standard') {
    return style
  }

  return `-${vendor}-${style}`
// vendor + style.charAt(0).toUpperCase() + style.substr(1)
}

// 阻止冒泡事件兼容写法
export const CancelBubble = event => {
  if (event.stopPropagation) {
    event.stopPropagation()
  } else {
    event.cancelBubble = true
  }
}

// 取消默认事件兼容
export function returnFalse(event) {
	if(event.preventDefault) {
		event.preventDefault()
	} else {
		window.event.returnValue = false;
	}
	return false
}
